package util.adapter;

import android.app.Activity;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wq.cycling.R;

import java.util.ArrayList;

import bean.EntityForSimple;
import co.lujun.androidtagview.TagContainerLayout;
import util.myview.CircleImageView;

/**
 * 维修商Adapter
 * author：wangqi on 2017/4/26 17:48
 * email：773630555@qq.com
 */
public class ShopParticularsAdapter extends BaseAdapter {

	private Activity mContext;
	private LayoutInflater mInflater;
	private ArrayList<EntityForSimple> mDatas;
	private String[] str={"态度很好","修的又快又好","价格很便宜"};

	public ShopParticularsAdapter(Activity context, ArrayList<EntityForSimple> mDatas) {
		mContext = context;
		this.mDatas = mDatas;
		mInflater = LayoutInflater.from(mContext);
	}

	@Override
	public int getCount() {
		return mDatas.size();
	}

	@Override
	public Object getItem(int position) {
		return mDatas.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.listview_shop_particulars_body_item,null);
			holder = new ViewHolder(convertView);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.tag.setBackgroundColor(Color.alpha(0));//整个背景色
		holder.tag.setBorderColor(Color.alpha(0));//整个容器的边框色，因为有默认值，所以我自己设为透明
		holder.tag.removeAllTags();
		for(int i=0;i<str.length;i++) {
			addView(str[i], holder.tag);
		}
		return convertView;
	}

	private static class ViewHolder {
		public TextView tv_name;
		public TagContainerLayout tag;
        public CircleImageView circleview;
		ViewHolder(View view) {
			tv_name = ((TextView) view.findViewById(R.id.tv_name));
			tag = ((TagContainerLayout) view.findViewById(R.id.tag));
			circleview = ((CircleImageView) view.findViewById(R.id.circleview));
		}
	}

	private void addView(String text,TagContainerLayout tag) {
		//添加自定义布局
		View inflate = LayoutInflater.from(mContext).inflate(R.layout.tag_item, null);
		((TextView) inflate.findViewById(R.id.textView)).setText(text);
		tag.addView(inflate);
	}

}
